package com.chixing.day15_map.homework;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;


public class CopyDemo {

    public void copyDemo(String oldPath, String newPath) {
        try {
            int bytesum = 0;
            int byteread = 0;
            File oldfile = new File(oldPath);
            if (oldfile.exists()) { //文件存在时
                InputStream inStream = new FileInputStream(oldPath); //读入原文件
                FileOutputStream os = new FileOutputStream(newPath);
                byte[] bytes = new byte[1444];
                int length;
                while ( (byteread = inStream.read(bytes)) != -1) {
                    bytesum += byteread; //字节数 文件大小
                    System.out.println(bytesum);
                    os.write(bytes, 0, byteread);
                }
                inStream.close();
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {

        String oldPath = "d://test1//hello.txt";
        String newPath = "d://test2//hello.txt";
        CopyDemo file = new CopyDemo();
        file.copyDemo(oldPath,newPath);
    }
}
